package com.zhanhong.opencvdemo.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;

import com.zhanhong.opencvdemo.R;
import com.zhanhong.opencvdemo.utils.ScreenUtils;
import com.zhanhong.opencvdemo.value.IntentKey;

public class TakePhotoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_take_photo);
        initView();
        initData();
    }

    private void initView() {
        findViewById(R.id.tv_back).setOnClickListener(v -> finish());
        View ivContainer = findViewById(R.id.iv_answer_sheet_container);
        ViewGroup.LayoutParams layoutParams = ivContainer.getLayoutParams();
        layoutParams.width = ScreenUtils.getScreenWidth() / 5 * 4;
        layoutParams.height = (int) (layoutParams.width * 1.5);
        ivContainer.setLayoutParams(layoutParams);
        findViewById(R.id.fl_take_photo).setOnClickListener(v -> {
            CameraView cameraView = findViewById(R.id.vcv_content);
            cameraView.getCamera().takePicture(null, null, (data, camera) -> {
                Intent intent = new Intent();
                intent.putExtra(IntentKey.KEY_PHOTO_IMAGE_ANGLE, cameraView.getCamBackAngle());
                intent.putExtra(IntentKey.KEY_PHOTO_IMAGE_BYTES, data);
                setResult(RESULT_OK, intent);
                finish();
            });
        });
    }

    private void initData() {

    }
}
